package com.sgb.kjwl.view.widget;

import android.content.Context;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.util.Log;
import android.widget.TextView;

import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.AlbumEntity;
import com.sgb.kjwl.view.ui.activity.self.publish.GoodsAlbumActivity;
import com.sgb.kjwl.view.ui.adapter.material.SelectAlbumAdapter;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.PopViewHolder;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;

import java.util.List;

public class SelectAlbumPopWindow extends BasePopWindow<String> {
    private RecyclerView netAlbumRecycler;
    private SelectAlbumAdapter adapter;
    private List<AlbumEntity> datas;
    private TextView tvCancel;
    private TextView tvPhoneAlbum;

    public SelectAlbumPopWindow(Context context) {
        super(context, DIR_DOWN_UP);
    }

    @Override
    protected int popLayout() {
        return R.layout.popwindow_select_album;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        netAlbumRecycler = holder.getPop().findViewById(R.id.net_album_recycler);
        tvCancel = holder.getPop().findViewById(R.id.tv_cancel);
        tvPhoneAlbum = holder.getPop().findViewById(R.id.tv_phone_album);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
        adapter = new SelectAlbumAdapter(mContext, null);
        netAlbumRecycler.setLayoutManager(linearLayoutManager);
        netAlbumRecycler.setAdapter(adapter);
        adapter.setOnItemClick(new AdapterOnItemClick<AlbumEntity>() {
            @Override
            public void onItemClick(AlbumEntity albumEntity, int position) {
                onResultClick.result(1, null, null);
                GoodsAlbumActivity.start(mContext, albumEntity.getId(), albumEntity.getName(), datas, position);
            }
        });
        tvPhoneAlbum.setOnClickListener(v -> {
            onResultClick.result(0, null, null);
        });
        tvCancel.setOnClickListener(v -> {
            dismiss();
        });
    }

    public void setData(List<AlbumEntity> datas) {
        this.datas = datas;
        if (datas.size() < 0) {
            return;
        }
        adapter.setDatas(datas);
    }
}
